//倒计时；
var time = function (timeStamp, timeStampOne, that) {
  var interval = null,
      totalSecond = timeStamp,
      oneTimeStame = timeStampOne,
      oldSecond = timeStamp;
  interval = setInterval(function () {
    // 秒数  
    var second = totalSecond; // 小时位  

    var hr = Math.floor(second / 3600);
    var hrStr = hr.toString();
    if (hrStr.length == 1) hrStr = '0' + hrStr; // 分钟位  

    var min = Math.floor((second - hr * 3600) / 60);
    var minStr = min.toString();
    if (minStr.length == 1) minStr = '0' + minStr; // 秒位  

    var sec = second - hr * 3600 - min * 60;
    var secStr = sec.toString();
    if (secStr.length == 1) secStr = '0' + secStr;
    that.setData({
      countDownHour: hrStr,
      countDownMinute: minStr,
      countDownSecond: secStr
    });
    totalSecond--;

    if (totalSecond <= oldSecond - oneTimeStame) {
      clearInterval(interval);

      if (oldSecond === oneTimeStame) {
        that.setData({
          countDownHour: '00',
          countDownMinute: '00',
          countDownSecond: '00'
        });
      }

      that.getSeckillConfig();
    }
  }.bind(that), 1000);
  that.setData({
    interval: interval
  });
}; //倒计时2；


var time2 = function (timeStamp, that) {
  var interval = null,
      totalSecond = timeStamp;
  interval = setInterval(function () {
    // 秒数  
    var second = totalSecond; // 小时位  

    var hr = Math.floor(second / 3600);
    var hrStr = hr.toString();
    if (hrStr.length == 1) hrStr = '0' + hrStr; // 分钟位  

    var min = Math.floor((second - hr * 3600) / 60);
    var minStr = min.toString();
    if (minStr.length == 1) minStr = '0' + minStr; // 秒位  

    var sec = second - hr * 3600 - min * 60;
    var secStr = sec.toString();
    if (secStr.length == 1) secStr = '0' + secStr;
    that.setData({
      countDownHour: hrStr,
      countDownMinute: minStr,
      countDownSecond: secStr
    });
    totalSecond--;

    if (totalSecond <= 0) {
      clearInterval(interval);
      that.setData({
        countDownHour: '00',
        countDownMinute: '00',
        countDownSecond: '00'
      });
    }
  }.bind(that), 1000);
  that.setData({
    interval: interval
  });
};

module.exports = {
  time: time,
  time2: time2
};